package com.example.controller;

import com.example.po.Sys_City;
import com.example.service.Sys_CityService;
import com.example.vo.CityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @auter czcjq
 * @date 2022/5/16 21:13
 */
@Controller
@RequestMapping("/city")
public class Sys_CityController {
    @Autowired
    private Sys_CityService sys_cityService;

    /**
     * 根据pid 查询city信息
     *
     */
    @ResponseBody
    @RequestMapping(value="selectCitiesById")
    public List<Sys_City> findCitiesByPid(@RequestParam(value="pid",defaultValue = "0") int pid){
       /* System.out.println("pid:"+pid);*/
        List<Sys_City> cities = sys_cityService.findCities(pid);
       /* System.out.println(cities);*/
        return cities;

    }
    /**
     * 根据pid 查询city信息
     *
     */
    @ResponseBody
    @RequestMapping(value="findCityNameByPid")
    public CityVo findCityNameByPid(int getid, int backid){
        Sys_City city1 = sys_cityService.findCityById(getid);
        Sys_City city2 = sys_cityService.findCityById(backid);
        CityVo vo = new CityVo();
        vo.setCode(1);
        Map map = new HashMap<>();
        map.put("getCity",city1);
        map.put("backCity",city2);
        vo.setInfo(map);
        return vo;

    }
}
